import type {
    PickerColumn,
    PickerColumnItem,
    PickerValue,
} from 'antd-mobile/es/components/picker-view'

/**
 * 将对象转为Picker需要的Columns数据
 * @param obj
 * @returns
 */
export const objToPickerArgs = (obj: object) => {
    const args: PickerColumnItem[] = []
    Object.entries(obj).forEach(([key, value]) => args.push({ label: value, value: key }))
    return args
}

/**
 * 根据选中值获取Picker对应的Label
 * @param columns Picker's Columns
 * @param values Selected Value
 * @returns
 */
export const getPickerSelectedLabel = (columns: PickerColumn[], values: PickerValue[]) => {
    if (values.length === 0 || columns.length === 0) return
    const value = values[0]
    const flatColumns = columns.flat() as PickerColumnItem[]
    const target = flatColumns.find(item => item.value === value)
    return target?.label || '-'
}
